package com.iswoak.netctoss.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.iswoak.netctoss.service.AdminInfoService;
import com.iswoak.netctoss.service.impl.AdminInfoServiceImpl;

/**
 * 登录操作
 * @author: yxt 
 * 2019年6月28日 下午5:15:12
 */
@WebServlet("/log/*")
public class LogServlet extends HttpServlet {
	//创建Service对象
	AdminInfoService adminInfoService = new AdminInfoServiceImpl();
	
	@Override
	protected void service(HttpServletRequest req, 
			HttpServletResponse resp) throws ServletException, IOException {
		//设置
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		String uri = req.getRequestURI();
		if(uri.endsWith("/login")) {
			login(req,resp);
		}
		
	}
	
	private  void login(HttpServletRequest req, 
			HttpServletResponse resp) throws ServletException, IOException {
//		得到请求参数
		String adminCode = "admin";
		String pwd = "123456";
		if(true) {//模拟登陆成功
			HttpSession session = req.getSession();
//			将账号存入session中
			List<String> modules = adminInfoService.findAllMouduleByAdminCode(adminCode);
			session.setAttribute("modules", modules);
			resp.sendRedirect(req.getContextPath()+"/index.jsp");
		}
		
	}

	
}
